<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>添加订单</title>
    <meta name="description" content="AdminLTE2定制版">
    <meta name="keywords" content="AdminLTE2定制版">

    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">

    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

    <!-- 页面meta /-->

    <link rel="stylesheet" href="/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="/plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="/plugins/ionicons/css/ionicons.min.css">
    <link rel="stylesheet" href="/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="/plugins/morris/morris.css">
    <link rel="stylesheet" href="/plugins/jvectormap/jquery-jvectormap-1.2.2.css">
    <link rel="stylesheet" href="/plugins/datepicker/datepicker3.css">
    <link rel="stylesheet" href="/plugins/daterangepicker/daterangepicker.css">
    <link rel="stylesheet" href="/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="/plugins/datatables/dataTables.bootstrap.css">
    <link rel="stylesheet" href="/plugins/treeTable/jquery.treetable.css">
    <link rel="stylesheet" href="/plugins/treeTable/jquery.treetable.theme.default.css">
    <link rel="stylesheet" href="/plugins/select2/select2.css">
    <link rel="stylesheet" href="/plugins/colorpicker/bootstrap-colorpicker.min.css">
    <link rel="stylesheet" href="/plugins/bootstrap-markdown/css/bootstrap-markdown.min.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/AdminLTE.css">
    <link rel="stylesheet" href="/plugins/adminLTE/css/skins/_all-skins.min.css">
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="/plugins/ionslider/ion.rangeSlider.css">
    <link rel="stylesheet" href="/plugins/ionslider/ion.rangeSlider.skinNice.css">
    <link rel="stylesheet" href="/plugins/bootstrap-slider/slider.css">
    <link rel="stylesheet" href="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.css">
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <!-- 页面头部 -->
<!--    <jsp:include page="header.jsp"/>-->
    <div  th:insert="~{pages/commons::header}"></div>
    <!-- 页面头部 /-->

    <!-- 导航侧栏 -->
<!--    <jsp:include page="sidebar.jsp"/>-->
    <div th:insert="~{pages/commons::siderbar}"></div>
    <!-- 导航侧栏 /-->

    <!-- 内容区域 -->
    <div class="content-wrapper">

        <!-- 内容头部 -->
        <section class="content-header">
            <h1>
                订单管理
                <small>订单信息</small>
            </h1>
            <ol class="breadcrumb">
                <li><a th:href="@{/}"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">订单管理</a></li>
                <li class="active">订单信息</li>
            </ol>
        </section>
        <!-- 内容头部 /-->

        <!-- 正文区域 -->
        <section class="content">

            <!--订单信息-->
            <div class="panel panel-default">
                <div class="panel-heading">订单信息</div>
                <div class="row data-type">
                    <form id="form1">

                        <div class="col-md-2 title">产品名称</div>
                        <div class="col-md-4 data" >
                            <select id="productId" name="productId"  onchange="changeMoney()" class="form-control select2"
                                    style="width: 100%;">
                                <option>请选择</option>
                                <option th:each="product,productStat:${products}" th:price="${product.getProductPrice()}" th:value="${product.id}">[[${product.productName}]]</option>
                            </select>
                        </div>

                        <div class="col-md-2 title">金额</div>
                        <div class="col-md-4 data">
                            <input type="text"  id="productPrice" class="form-control" value="请先产品" readonly>
                        </div>

                        <div class="col-md-2 title">订单状态</div>
                        <div class="col-md-4 data">
                            <select name="orderStatus"  class="form-control" style="height:35px">
                                <option value="1">已支付</option>
                                <option value="0">未支付</option>
                            </select>
                        </div>

                        <div class="col-md-2 title">人数</div>
                        <div class="col-md-4 data">
                            <select name="peopleCount" id="peopleCount" onchange="changeInfo()" class="form-control"
                                    style="height:35px">
                                <option value="1" selected="selected">1人</option>
                                <option value="2">2人</option>
                            </select>
                        </div>


                        <div class="col-md-2 title">支付类型</div>
                        <div class="col-md-10 data">
                            <select name="payType" class="form-control" style="height:35px">
                                <option value="0">支付宝</option>
                                <option value="1">微信</option>
                                <option value="2">现金</option>
                            </select>
                        </div>


                        <div class="col-md-2 title rowHeight3x text-center" style="height: 80px;">其他信息</div>
                        <div class="col-md-10 data rowHeight3x text-center" style="height: 80px;">
                            <textarea name="orderDesc" class="form-control" rows="3" placeholder="其他信息"></textarea>
                        </div>
                    </form>

                    <div class="col-md-12 title">会员信息（联系方式）</div>
                    <!--<%--联系方式--%>-->
                    <form id="form4">
                        <div class="col-md-2 title">姓名</div>
                        <div class="col-md-4 data">
                            <input type="text" name="name" class="form-control" placeholder="请输入姓名" value="">
                        </div>

                        <div class="col-md-2 title">昵称</div>
                        <div class="col-md-4 data">
                            <input type="text" name="nickName" class="form-control" placeholder="请输入昵称" value="">
                        </div>

                        <div class="col-md-2 title">手机号</div>
                        <div class="col-md-4 data">
                            <input type="text" name="phoneNum" class="form-control" placeholder="请输入手机号" value="">
                        </div>

                        <div class="col-md-2 title">邮箱</div>
                        <div class="col-md-4 data">
                            <input type="text" name="email" class="form-control" placeholder="请输入邮箱" value="">
                        </div>
                    </form>

                   <!-- <%--                      游客信息--%>-->
                    <div class="col-md-12 title">订单游客成员信息</div>
                    <div id="formAll">
                        <form id="form2">
                            <div class="col-md-2 title">姓名</div>
                            <div class="col-md-4 data">
                                <input type="text" name="name" class="form-control" placeholder="请输入姓名" value="">
                            </div>


                            <div class="col-md-2 title">性别</div>
                            <div class="col-md-4 data">
                                <select name="sex" class="form-control" style="height:35px">
                                    <option value="男">男</option>
                                    <option value="女">女</option>
                                </select>
                            </div>

                            <div class="col-md-2 title">联系方式</div>
                            <div class="col-md-10 data">
                                <input type="text" name="phoneNum" class="form-control" placeholder="请输入联系方式" value="">
                            </div>


                            <div class="col-md-2 title">证件类型</div>
                            <div class="col-md-4 data">
                                <select name="credentialsType" class="form-control" style="height:35px">
                                    <option value="0">身份证</option>
                                    <option value="1">护照</option>
                                    <option value="2">军官证</option>
                                </select>
                            </div>

                            <div class="col-md-2 title">证件号码</div>
                            <div class="col-md-4 data">
                                <input type="text" name="credentialsNum" class="form-control" placeholder="请输入证件号"
                                       value="">
                            </div>

                            <div class="col-md-2 title">游客类型</div>
                            <div class="col-md-10 data">
                                <select name="travellerType" class="form-control" style="height:35px">
                                    <option value="0">成人</option>
                                    <option value="1">儿童</option>
                                </select>
                            </div>
                        </form>
                        <div id="temp" class="col-md-12 title></div>


                        <div class=" col-md-12 title></div>
                        <div class="col-md-12 data text-center">
                            <button type="button" onclick="commitAll()" class="btn bg-maroon">保存</button>
                            <button type="button" class="btn bg-default" onclick="history.back(-1);">返回</button>
                        </div>
                    </div>
                </div>

            </div>
        <!--订单信息/-->
        </section>
        <!-- 正文区域 /-->
    </div>
        <!-- 底部导航 -->
        <!--<jsp:include page="footer.jsp"/>-->
        <div th:insert="~{pages/commons::footer}"></div>
        <!-- 底部导航 /-->
</div>
</body>

<script type="text/javascript" src="/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="/plugins/jQueryUI/jquery-ui.min.js"></script>
<script>
    $.widget.bridge('uibutton', $.ui.button);
</script>
<script src="/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="/plugins/raphael/raphael-min.js"></script>
<script src="/plugins/morris/morris.min.js"></script>
<script src="/plugins/sparkline/jquery.sparkline.min.js"></script>
<script src="/plugins/jvectormap/jquery-jvectormap-1.2.2.min.js"></script>
<script src="/plugins/jvectormap/jquery-jvectormap-world-mill-en.js"></script>
<script src="/plugins/knob/jquery.knob.js"></script>
<script src="/plugins/daterangepicker/moment.min.js"></script>
<script src="/plugins/daterangepicker/daterangepicker.js"></script>
<script src="/plugins/daterangepicker/daterangepicker.zh-CN.js"></script>
<script src="/plugins/datepicker/bootstrap-datepicker.js"></script>
<script src="/plugins/datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script src="/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<script src="/plugins/fastclick/fastclick.js"></script>
<script src="/plugins/iCheck/icheck.min.js"></script>
<script src="/plugins/adminLTE/js/app.min.js"></script>
<script src="/plugins/treeTable/jquery.treetable.js"></script>
<script src="/plugins/select2/select2.full.min.js"></script>
<script src="/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.zh-CN.js"></script>
<script src="/plugins/bootstrap-markdown/js/bootstrap-markdown.js"></script>
<script src="/plugins/bootstrap-markdown/locale/bootstrap-markdown.zh.js"></script>
<script src="/plugins/bootstrap-markdown/js/markdown.js"></script>
<script src="/plugins/bootstrap-markdown/js/to-markdown.js"></script>
<script src="/plugins/ckeditor/ckeditor.js"></script>
<script src="/plugins/input-mask/jquery.inputmask.js"></script>
<script src="/plugins/input-mask/jquery.inputmask.date.extensions.js"></script>
<script src="/plugins/input-mask/jquery.inputmask.extensions.js"></script>
<script src="/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="/plugins/datatables/dataTables.bootstrap.min.js"></script>
<script src="/plugins/chartjs/Chart.min.js"></script>
<script src="/plugins/flot/jquery.flot.min.js"></script>
<script src="/plugins/flot/jquery.flot.resize.min.js"></script>
<script src="/plugins/flot/jquery.flot.pie.min.js"></script>
<script src="/plugins/flot/jquery.flot.categories.min.js"></script>
<script src="/plugins/ionslider/ion.rangeSlider.min.js"></script>
<script src="/plugins/bootstrap-slider/bootstrap-slider.js"></script>
<script src="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="/plugins/bootstrap-datetimepicker/locales/bootstrap-datetimepicker.zh-CN.js"></script>


<!--<%--序列化form--%>-->
<script type="text/javascript"  src="/jst/serializeObject.js"></script>

<script type="text/javascript" th:inline="javascript">
    var contextPath= [[${#httpServletRequest.getContextPath()}]];
    $(document).ready(function () {
        // 选择框
        $(".select2").select2();

        // WYSIHTML5编辑器
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });


    // 设置激活菜单
    function setSidebarActive(tagUri) {
        var liObj = $("#" + tagUri);
        if (liObj.length > 0) {
            liObj.parent().parent().addClass("active");
            liObj.addClass("active");
        }
    }


    $(document).ready(function () {
        $('#datepicker-a3').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });


    $(document).ready(function () {
        $('#datepicker-a6').datepicker({
            autoclose: true,
            language: 'zh-CN'
        });
    });


    $(document).ready(function () {
        // 激活导航位置
        setSidebarActive("order-manage");
    });

    /*根据产品动态修改产品价格*/
    function changeMoney() {
        // var pid = document.getElementById("productId").selectedIndex;
        // var tmp=[];
       var productPrice = $("select[name='productId'] option:checked").attr("price");
       if(productPrice!=null){
           $("#productPrice").val(productPrice);
       }else {
           $("#productPrice").val("请先选择产品");
       }


    // <c:forEach items="${productsAdd}" var="product">
    //     tmp.push(${product.productPrice})
    //     </c:forEach>
    //     if(pid==0){
    //         $("#productPrice").val("请先选择产品")
    //     }else {
    //         $("#productPrice").val(tmp[pid-1])
    //     }
    }

    /*根据人数动态生成表单*/
    function changeInfo() {
        if ($("#peopleCount").val() == 2) {
            $("#temp").after("<form id=\"form3\">\n" +
                "<div class=\"col-md-12 title\">订单游客成员信息</div>" +
                "                                        <div class=\"col-md-2 title\">姓名</div>\n" +
                "                                        <div class=\"col-md-4 data\">\n" +
                "                                            <input type=\"text\" name=\"name\" class=\"form-control\" placeholder=\"请输入姓名\" value=\"\">\n" +
                "                                        </div>\n" +
                "\n" +
                "\n" +
                "                                        <div class=\"col-md-2 title\">性别</div>\n" +
                "                                        <div class=\"col-md-4 data\">\n" +
                "                                            <select name=\"sex\" class=\"form-control\" style=\"height:35px\">\n" +
                "                                                <option value=\"男\">男</option>\n" +
                "                                                <option value=\"女\">女</option>\n" +
                "                                            </select>\n" +
                "                                        </div>\n" +
                "\n" +
                "                                        <div class=\"col-md-2 title\">联系方式</div>\n" +
                "                                        <div class=\"col-md-10 data\">\n" +
                "                                            <input type=\"text\" name=\"phoneNum\" class=\"form-control\" placeholder=\"请输入联系方式\" value=\"\">\n" +
                "                                        </div>\n" +
                "\n" +
                "\n" +
                "                                        <div class=\"col-md-2 title\">证件类型</div>\n" +
                "                                        <div class=\"col-md-4 data\">\n" +
                "                                            <select name=\"credentialsType\" class=\"form-control\" style=\"height:35px\">\n" +
                "                                                <option value=\"0\">身份证</option>\n" +
                "                                                <option value=\"1\">护照</option>\n" +
                "                                                <option value=\"2\">军官证</option>\n" +
                "                                            </select>\n" +
                "                                        </div>\n" +
                "\n" +
                "                                        <div class=\"col-md-2 title\">证件号码</div>\n" +
                "                                        <div class=\"col-md-4 data\">\n" +
                "                                            <input type=\"text\" name=\"credentialsNum\" class=\"form-control\" placeholder=\"请输入证件号\" value=\"\">\n" +
                "                                        </div>\n" +
                "\n" +
                "                                        <div class=\"col-md-2 title\">游客类型</div>\n" +
                "                                        <div class=\"col-md-10 data\">\n" +
                "                                            <select name=\"travellerType\" class=\"form-control\" style=\"height:35px\">\n" +
                "                                                <option value=\"0\">成人</option>\n" +
                "                                                <option value=\"1\">儿童</option>\n" +
                "                                            </select>\n" +
                "                                        </div>\n" +
                "                                    </form>");
        } else if ($("#peopleCount").val() == 1) {
            $("#form3").remove();
        }
    }

    function commitAll(){
        var allMap = {};
        var travellerList = [];

        var order = $("#form1").serializeObject();

        allMap.orders=order;
        //orders必须和实体类中的属性名相同才行,
        // 不能先用stringIfy方法将orders转换为json字符串

        /*会员信息*/
        var member = $("#form4").serializeObject();
        allMap.member=member;

        /*乘客信息1*/
        var form2 = $("#form2").serializeObject()
        travellerList.push(form2);
        //没有填写第二个人的信息，排除掉
        if($("#form3")!=null){
            /*乘客信息2*/
            var form3 = $("#form3").serializeObject()
            for(var each in form3){
                if(each!=null){
                    travellerList.push(form3);
                    break;
                }
            }
        }

        allMap.travellerList = travellerList;
        //travellerList必须和实体类中的属性名相同才行,

        var datas =JSON.stringify(allMap);

        $.ajax({url:contextPath+"/orders/addOrder",
            type:"POST",
            contentType:"application/json;charset=utf-8",
            data:datas,
            traditional:true,
            success:function (){
                // alert("success")
                location.href = contextPath+"/orders/getOrders";
            },
            error:function (){
                alert("error");
            }
        })

    }
</script>


</html>